package com.baymax.test.scene.provider

import android.content.ComponentName
import android.content.ContentProvider
import android.content.ContentValues
import android.content.Intent
import android.database.Cursor
import android.net.Uri
import android.os.Bundle
import android.util.Log
import kotlinx.coroutines.*
import kotlinx.coroutines.rx2.asCompletable
import java.lang.UnsupportedOperationException
import kotlin.coroutines.CoroutineContext

class TestProvider : ContentProvider() ,CoroutineScope{
    override val coroutineContext: CoroutineContext = Dispatchers.IO

    override fun delete(uri: Uri, selection: String?, selectionArgs: Array<String>?): Int {
        // Implement this to handle requests to delete one or more rows.
        throw UnsupportedOperationException("Not yet implemented")
    }

    override fun getType(uri: Uri): String? {
        // TODO: Implement this to handle requests for the MIME type of the data
        // at the given URI.
        throw UnsupportedOperationException("Not yet implemented")
    }

    override fun insert(uri: Uri, values: ContentValues?): Uri? {
        // TODO: Implement this to handle requests to insert a new row.
        throw UnsupportedOperationException("Not yet implemented")
    }

    override fun onCreate(): Boolean {
        // TODO: Implement this to initialize your content provider on startup.
        return false
    }

    override fun query(
        uri: Uri, projection: Array<String>?, selection: String?,
        selectionArgs: Array<String>?, sortOrder: String?
    ): Cursor? {
        // TODO: Implement this to handle query requests from clients.
        throw UnsupportedOperationException("Not yet implemented")
    }

    override fun update(
        uri: Uri, values: ContentValues?, selection: String?,
        selectionArgs: Array<String>?
    ): Int {
        // TODO: Implement this to handle requests to update one or more rows.
        throw UnsupportedOperationException("Not yet implemented")
    }
    private val TAG = "test-provider"

    override fun call(method: String, arg: String?, extras: Bundle?): Bundle? {
        runBlocking {
            Log.d(TAG, "call: start")
            delay(10000)
            Log.d(TAG, "call: end")
        }


        val intent = Intent()
        intent.setComponent(
            ComponentName(
                "com.tencent.gamereva",
                "com.tencent.gamereva.UfoTVHomePage"
            )
        )
        intent.putExtra("iGameID" ,"95952")
        intent.putExtra("iChannel" ,"415")
        requireContext().startActivity(intent)
        return super.call(method, arg, extras)
    }

    override fun call(authority: String, method: String, arg: String?, extras: Bundle?): Bundle? {
        return super.call(authority, method, arg, extras)
    }
}